#ifndef LOG_MANAGER_H
#define LOG_MANAGER_H

#include <QObject>
#include <QFile>
#include <QTextStream>
#include <QDateTime>
#include <QMutex>
#include <QDir>

class LogManager : public QObject
{
    Q_OBJECT

public:
    static LogManager* getInstance();
    void init(const QString& logDir = "./logs", int keepDays = 7);
    void cleanup();

private:
    LogManager(QObject* parent = nullptr);
    ~LogManager();

    void openLogFile();
    void closeLogFile();
    void checkAndRotateLogFile();
    void cleanOldLogs();
    static void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg);

private:
    static LogManager* instance_;
    QFile logFile_;
    QTextStream logStream_;
    QMutex mutex_;
    QString logDir_;
    QString currentDate_;
    int keepDays_;
};

#endif // LOG_MANAGER_H 